home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15865 < prev    next >
Encoding:
Text File  |  1996-08-05  |  18.8 KB  |  349 lines

  1. Path: news.vanderbilt.edu!news
  2. From: "Mikhail V. Saparov" <misha@vuse.vanderbilt.edu>
  3. Newsgroups: comp.lang.c,comp.lang.c++,sci.math,rec.puzzle
  4. Subject: programming contest
  5. Date: Mon, 08 Apr 1996 11:24:22 -0500
  6. Organization: Vanderbilt University, Nashville, TN, USA
  7. Message-ID: <31693DB6.41C6@mplik.ru>
  8. NNTP-Posting-Host: hf1.vuse.vanderbilt.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1; name="gersh"
  11. Content-Transfer-Encoding: 8bit
  12. X-Mailer: Mozilla 3.0b2 (X11; I; AIX 2)
  13. Content-Disposition: inline; filename="gersh"
  14.  
  15. ===============================================================================
  16.  
  17.            ******************************************************
  18.            *    Association of Urals State University Alumni    *
  19.            *      USU Mathematics and Mechanics Department      *
  20.            *        Student's Scientific Computer Society       *
  21.            ******************************************************
  22.  
  23.                                   presents
  24.                international computer programming competition
  25.  
  26.                             "KARPINSK TRAM - 96"
  27.                             ~~~~~~~~~~~~~~~~~~~~
  28.        dedicated to second anniversary since abolishment of tram route
  29.                           in the town of Karpinsk.
  30.  
  31.      Graph algorithms  lovers will  have a  chance to  show their  worth, have
  32. fun, and possibly get a PRIZE by taking part in the programming contest.   The
  33. problem is not hard to understand, so anyone can try solving it - from  school
  34. students to professors.
  35.      The  organizers  sincerely  appreciate  help  provided  by Association of
  36. Urals State  University Alumni  for becoming  general sponsor  of the contest,
  37. and  Ural   Relcom  company   for  providing   communication  resources    and
  38. informational support.
  39.  
  40.  
  41.                             One track tram route.
  42.                             ~~~~~~~~~~~~~~~~~~~~~
  43.      For a long  time there was  a unique system  of tram routes  in Karpinsk.
  44. What made it unique  was the only pair  of rails so that  trams were following
  45. it in both directions.  To  prevent accidents, at several points of  the route
  46. double track  section was  established, so  that two  trams going  in opposite
  47. directions could safely pass  each other.  If  one of the trams  would come to
  48. the passing track first,  he would have to  wait there until the  one going to
  49. the opposite direction arrives.
  50.      The authors  found it  interesting to  create an  algorithm for  building
  51. schedules  for  such   transportation  schemes.    The  generalized   problem,
  52. formulated in terms of graph theory, is offered to reader's attention.
  53.  
  54.  
  55.                                 The problem.
  56.                                 ~~~~~~~~~~~~
  57.      Consider  a  non-oriented  connected  graph  without  loops  and multiple
  58. edges.  For convenience let us introduce  some terms.  A vertex of degree  one
  59. we  will  call  terminal.   A  vertex  of  degree  two will be either stage or
  60. passing track.  The difference is that  on a passing track two trams going  in
  61. the opposite  directions can  pass each  other; on  a station  they cannot.  A
  62. vertex of degree  three or more  is called junction.  A vertex that  is either
  63. junction, stage or passing track is called station.
  64.      Later we will  suppose that the  given graph contains  not lass than  two
  65. terminals.   Route  is  a  sequence  of  vertexes  satisfying  the   following
  66. transport conditions:  any two  consequent route vertexes are connected  by an
  67. edge of the  graph; the first  vertex of the  route is a  terminal and is  the
  68. same with the last one; exactly one of the rest vertexes of the route is  also
  69. a terminal, and these two terminals are  not the same (The meaning of this  is
  70. that route is a path from the  first terminal to the second one and  back, and
  71. the paths there and back are not necessarily the same). If V(1) ... V(n) is  a
  72. route, then for any i from the set {2,...,n-1} holds
  73.                   ( deg V(i) != 1  ==> V(i-1) != V(i+1) ),
  74. where V(i) means the  vertex, which has the  order i in the  route ); The
  75. meaning of this restriction is that  trams can turn around only on  terminals.
  76. (Here notation deg V is used to denote degree of vertex V).
  77.      Route Schedule is a  function S(V), that maps  any junction and   passing
  78. track  into  a  non-negative  integer.   Note,  that  if  some  vertex is used
  79. several times in the route, it can every time map to a different integer.  The
  80. value of the function  is equal to the  number of trams going  to the opposite
  81. direction, that our tram has to pass before leaving the particular vertex.   A
  82. tram is considered to be going to the opposite direction if it comes from  the
  83. edge, where  the yielding  tram is  required go.   For our  convenience let us
  84. suppose S(V)  function to  be equal  zero on  all stages  and terminals.  Each
  85. tram has its own route.  At the beginning all trams are at the first  vertexes
  86. of the corresponding routes.   If at some moment a  tram is at vertex V,  then
  87. the edge by which it came to V (if V is a stage, then both edges are  incident
  88. to V) is (are) blocked for all other trams at this moment.
  89.      Let us describe movement of a fixed tram T.  Let the tram came to  vertex
  90. V and U is the next vertex in  the route. Then The tram is waiting until  S(V)
  91. other trams pass  edge UV.   This includes the  tram (if there  was one) which
  92. followed edge UV and was in V vertex  when tram T came there.  Let S(V)  trams
  93. have passed (or S(V)=0). If edge VU  is blocked, then tram T is waiting  until
  94. it is free.  If the tram is not waiting, it follows to vertex U.
  95.      Time is measured in steps.  On  each step all trams that are not  waiting
  96. make a simultaneous move.
  97.      Transportation schedule is a set  of route schedules, that allows  to get
  98. from  any  station  to  any  other  station  (maybe  changing  trams  on  some
  99. stations).   Any two  starting points  of different  routes in  transportation
  100. schedule must not be the same.  At the beginning (step zero) every tram is  at
  101. the  staring  vertex  of  the   corresponding  route.   Working  time  for   a
  102. transportation schedule  is a  minimum number  of steps  required so that each
  103. participating tram finishes not less  than three full routes (The  first route
  104. of a  tram may  differ from  the rest  ones because  of different positions of
  105. other trams at the  starting moment.  That's  why second and third  routes may
  106. take longer (or shorter) than the first one). If some transportation  schedule
  107. does not let all  trams to complete three  full routes, working time  for this
  108. schedule  is  considered  to  be  infinity.   All  vertexes  of  degree two in
  109. original  graph  are  stages.   Operation  of  adding  a  passing route is the
  110. procedure  of  attaching  to  the  graph  a  new  vertex W and substituting an
  111. existing edge UV  with a pair  of edges UW  and WV.   After this operation the
  112. new vertex W is a  passing route.  Let us  call a graph valid if  it either is
  113. the same  with the  original graph,  or can  be derived  from it  by adding  a
  114. finite number of  passing routes.   The problem is  to build a  transportation
  115. schedule that has minimal  working time among all  valid graphs.  It  has been
  116. proven (see  appendix) that  for any  original graph  with M  terminals it  is
  117. possible to  build a  valid graph,  which has  a transportation  schedule with
  118. finite  working  time  and  which  can  be  derived from the original graph by
  119. adding not  more than  M-1 passing  routes.   Thus, the  problem stated  above
  120. always has a solution.
  121.  
  122.  
  123.                              Contest conditions.
  124.                              ~~~~~~~~~~~~~~~~~~~
  125.      The contest  is open  to everyone.   To participate  one should  write  a
  126. program that for a given graph will built some valid graph and  transportation
  127. schedule  for  it.   The  program  must  be  submitted to contest organization
  128. committee before the due date stated  below.  Every participant is allowed  to
  129. submit no more than two programs for the competition.
  130.      Several test graph  will be offered  to participating programs.   On each
  131. of them working time of the transportation schedule built by programs will  be
  132. measured.  If a  program is unable to  generate transportation schedule for  a
  133. given graph, then  the corresponding working  time is assumed  to be equal  to
  134. doubled maximum working time for this graph among all participating  programs.
  135. If for  some graph  no program  is able  to generate  transportation schedule,
  136. than for  all programs  the working  time for  this graph  is considered to be
  137. zero.  The number of vertexes of the test graph will not be more than twenty.
  138.      A program,  which will  have minimal  sum of  working times  for all test
  139. graphs, will  be declared  the winner.   The author  of winning  program  will
  140. receive the prize.  For programs  ranked first, second and third, the  authors
  141. will receive contest diplomas.
  142.      For those  who wants  to compete  with computers  there is  an additional
  143. contest.   On  this  contest  the  same  test  graph  will be offered to human
  144. beings.   Participants will  need to  submit transportation  schedules to  the
  145. organization committee,  one schedule  for each  given graph.   The  solutions
  146. will be scored in the same way as the program-generated ones.  The winners  of
  147. this contest will be awarded with diplomas.
  148.      To participate in the additional contest one need to submit to
  149. organization committee an application in the following form:
  150.  
  151. 1.name
  152. 2.city and country
  153. 3.school or organization
  154. 4.electronic mail address
  155. 5.regular address (for diploma)
  156.  
  157.      Besides of the above, it is a good idea to provide any extra  information
  158. about yourself that you  consider appropriate.  The  test graphs will be  sent
  159. to participants by email ONLY.  In  addition they will be published on WWW  at
  160. "http://www.mplik.ru/~sg/tramk"   and   on   the   bulletin   board  near  USU
  161. Mathematics and Mechanics department dean's office.
  162.  
  163.  
  164.                             Program requirements
  165.                             ~~~~~~~~~~~~~~~~~~~~
  166.      The program must be submitted in the form of C or C++ source code all in
  167. a single file.
  168.      The program must be portable, i.e. it must not depend on such parameters
  169. as length in bits of int or char, CPU command set, etc.
  170.      The file must start with a comment, containing the contest application
  171. in the form as shown above for additional contest.
  172.      The program will be compiled with gnu gcc/g++ under UNIX.  Program that
  173. will not compile or link will not take part in the contest.
  174.      The program must take input from standard input stream (stdin) and write
  175. the results to standard output stream (stdout).  Using of any other files,
  176. including temporary ones, is prohibited.
  177.      The time that program will work is limited.  The maximum allowed time of
  178. calculations will be supplied to program along with input data.  The program
  179. may check the time spent using standard library routines (e.g.  gmtime() ).
  180. After the maximum allowed time has passed, the program will be forcibly
  181. stopped.  In this case the program will not be run again.
  182.      The program that does not provide upon completion a transportation
  183. schedule in the format described below, or finishes with run-time error is
  184. considered to be unable to generate transportation schedule for the given
  185. graph.
  186.      The number of passing tracks added by the program must not be greater
  187. that the doubled number of vertexes in the given graph.
  188.      If working time of the transportation schedule built by the program is
  189. greater than 10*N*N, where N is a number of vertexes of the given graph, then
  190. the program is considered to be unable to generate transportation schedule
  191. for the given graph.
  192.  
  193.  
  194.                               Input data format
  195.                               ~~~~~~~~~~~~~~~~~
  196. maximum allowed calculation time (in minutes)
  197. the number of vertexes in the graph
  198. Graph adjacency list
  199.  
  200. For each vertex of the graph in adjacency list there is a line:
  201. vertex_name: vertex_name vertex_name ... vertex_name
  202. where the left  one is the  current vertex, and  after the colon  there is the
  203. list  of  vertexes,   adjacent  with  it.   There  are  no  any other lines in
  204. adjacency list .
  205.      The name of the vertex  does not contain spaces, tabulation,  punctuation
  206. marks and starts with a letter.
  207. Example. For a graph, consisting of two terminals, connected with an edge,
  208. the input file fill be the following:
  209. 15
  210. 2
  211. V1: V2
  212. V2: V1
  213.  
  214.  
  215.                              Output data format
  216.                              ~~~~~~~~~~~~~~~~~~
  217. The number of passing tracks added
  218. The list of passing tracks added
  219. The list of routes
  220.  
  221. The list of passing tracks added consists of pairs:
  222. vertex_name vertex_name
  223. where the named vertexes  define the edge where  the new passing track  should
  224. be placed.  The newly added  passing tracks are automatically given the  names
  225. R1, R2,  ... .  If two  passing tracks  must be  added to  the same  edge, the
  226. corresponding part of the list must look like this:
  227. vertex_name vertex_name
  228. vertex_name passing_track_name
  229. i.e., the second passing track is placed onto the new edge created after
  230. adding the first one.
  231.      The list of routes looks like this:
  232. <empty line>
  233. terminal_name: 0
  234. vertex_name: number
  235. ...
  236. vertex_name: number
  237. terminal_name: 0
  238. <empty line>
  239. terminal_name: 0
  240. ... and so on.
  241.  
  242.  
  243.      The strings between empty lines define a route, the numbers after  colons
  244. define the  schedule function  for the  route.   For stages  and terminals the
  245. numbers must be zeros.  The list ends with two empty lines.
  246. Example. For the input file above the resulting output may be the following:
  247. 2
  248. V1 V2
  249. V2 R1
  250.  
  251. V1: 0
  252. R1: 0
  253. R2: 0
  254. V2: 0
  255. R2: 0
  256. R1: 0
  257. V1: 0
  258.  
  259.  
  260.  
  261.                           Due dates and coordinates
  262.                           ~~~~~~~~~~~~~~~~~~~~~~~~~
  263.      Programs must be  received by the  organization committee not  later than
  264. May 19, 1996.   Application for participating  in the additional  contest must
  265. also be received before this date.  Test graph will be published on  May 20th.
  266. Works  (transportation  schedules)  for  additional  contest must be submitted
  267. till May  26th. The  contests results  will be  published as  soon as they are
  268. ready.
  269.      The  following  way   of  delivering  works   and  applications  to   the
  270. organization committee  exist:
  271.  - send by  email on  address games@www.mplik.ru with subject  line  "Karpinsk
  272. Tram-96";
  273.  - send   by regular   mail on   a 3.5" 1.44M  diskette in   IBM PC  format on
  274. address: "Karpinsk  Tram-96", Mathematics  and Mechanics  department,   Dean's
  275. office,  Urals   University, 51  Lenina  Ave, Ekaterinburg, 620083,  Russia.
  276. Instead of  sending   by mail,  the   envelope may  be brought  to the  dean's
  277. office in person. In any  case, the diskette will   not be  returned   to  the
  278. participant.    deliver in   person  to  the organization committee  (math and
  279. mechanics USU dept., group MGMT-5). In this  case it  will be possible to  get
  280. the diskettes  back by   requesting them  in person   during a  week after the
  281. contest has ended.
  282.      All  possible  questions  and  comments  should  be  sent  to  the  above
  283. addresses.  Answers  to  frequently  asked  questions  and  other   up-to-date
  284. information will be available at  "http://www.mplik.ru/~sg/tramk".
  285.  
  286.  
  287.                        Contest organization committee
  288.                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  289. Sergey Gershtein, sg@mplik.ru. Urals University master's program student.
  290. Eugeny Shtykov, eug@kontur.e-burg.su. Urals Univ. master's program student.
  291.  
  292.  
  293.                                   Appendix
  294.                                   ~~~~~~~~
  295.      THEOREM. For any given graph with  M>1 terminals it is possible to  built
  296. a valid  graph for  which has  a transportation  schedule with  finite working
  297. time and which can be derived from the original graph by adding not more  than
  298. M-1 passing tracks.
  299.      Let us preface the proof with a auxiliary definition and lemma.
  300.      DEFINITION.    Let us   denote route   beginning with   terminal V    and
  301. going  through  terminal  U  with  M(U,V).  We   will use term cyclic stations
  302. covering  of  graph  G   with  set   of  terminals   δ  =   {V1, ..., Vn}  for
  303. collection of routes M(V1,V2), M(V2,V3), ..., M(Vn,V1),  which covers all  the
  304. stations.
  305.      LEMMA. Cyclic stations covering exists for any given graph.
  306.      PROOF OF THE LEMMA. Let us make  our proof by induction on the number  of
  307. stages in the graph. The base of induction is obvious: for zero stages in  the
  308. graph any collection of routes M(V1,V2), M(V2,V3),  , M(Vn,V1) will be  cyclic
  309. stations  covering.    Existence  of  such   collection  follows  from   graph
  310. connectivity.   Consider  a  graph  with  P  stages.   According  to induction
  311. hypothesis we  can build  cyclic stations  covering for  arbitrary chosen  P-1
  312. stages.  Denote the  remaining stage with W,  and the incident edges  with  UW
  313. and VW.   If W belongs  to some route,  the covering built  is the sought one.
  314. Suppose it does  not.  Let  in the graph  there is a  cycle W(0)=W, W(1), ...,
  315. W(t)=W.  We can find a path U(1), ..., U(n), that connects some vertex of  the
  316. cycle with a junction of some route.  Let k is the greatest number, such  that
  317. vertex U(k)=W(s) belongs to our cycle,  and m is the lowest number,  such that
  318. m greater or equal than k and  vertex U(m) belongs to an existing route.   Let
  319. this  route  is  V(i),  ...,  U(m),  ...,  V(i).  We  will  change it into the
  320. following:  V(i), ..., U(m),  U(m-1), ..., U(k)=W(s), W(s+1), ...,  W(t-1), W,
  321. W(1), ...,  W(s)=U(k), U(k+1),  ..., U(m-1),  U(m), ...,  V(i). The  resulting
  322. collection of  routes is  the sought  covering.   Let W  is a  cutpoint of the
  323. graph.   It  is  easy  to  see  that  in  this  case  one of the two connected
  324. components created when removing vertex  W, contains all the terminals  of the
  325. original graph.  Obviously, if it were not true, there would be no way to  get
  326. from one component to the second one.  Degree of each vertex in the  component
  327. without terminals  is not  less than  two, and  hence there  is a cycle there.
  328. Using the cycle, any  route can be modified  as shown above, and  the modified
  329. route will necessarily pass vertex W. The lemma is proven.
  330.      PROOF  OF  THE  THEOREM.  Let  V1,  ...,  Vn  are  all  terminals  of the
  331. original graph. According  to the above  lemma there exists  a cyclic stations
  332. covering M(V1,V2), M(V2,V3), ..., M(Vn,V1).  We will add one passing track  to
  333. edges that are  incident to vertexes  V2, ..., Vn,  and include these  passing
  334. tracks into  corresponding points  of the  covering routes.   The function  of
  335. route  schedule  will  be  equal  to  zero  everywhere besides the newly added
  336. passing  tracks,  on  which  it  will  be  equal  to  one.  The transportation
  337. schedule obtained solves  our problem because  according to it  all trams take
  338. turns moving  along their  routes and  do not  interfere with  each other. The
  339. theorem is proven.
  340.  
  341.  
  342.  
  343. -----------------------------------------------------------------------
  344.   Sergey Gershtein        sg@mplik.ru                    Ekaterinburg
  345.   Ural-Relcom, Ltd.       http://www.mplik.ru/~sg        Russia
  346. -----------------------------------------------------------------------
  347.  
  348.  
  349.